package task.manager;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * 
 * @author Harrison Saylor, Aaron Mead, Marc Huet, Greg Ruskin
 * @version 1.0
 */
public class TaskList implements Serializable {
	
	private static final long serialVersionUID = 1;
	private List<Task> taskList;
	
	/**
	 * TaskList default constructor.
	 */
	public TaskList() {
		taskList = new ArrayList<Task>();
	} // End of TaskList constructor.
	
	/**
	 * Adds a task to the task list.
	 * 
	 * @param task Task to add to the task list.
	 */
	public void addTask(Task task) {
		taskList.add(task);
	} // End of addTask method.
	
	
	public Task removeTask(String taskName){
		for(int i = 0;i<taskList.size();i++){
			if(taskList.get(i).getTitle().equals(taskName)){
				return taskList.remove(i);
			}
		}
		return null;
	}
	
	public String[] toArray(){
		String[] tempArr = new String[taskList.size()];
		
		for(int i = 0;i<taskList.size();i++){
			tempArr[i] = taskList.get(i).getTitle();
		}
		
		return tempArr;
	}

	public Task getTask(String taskName) {
		for(int i = 0;i<taskList.size();i++){
			if(taskList.get(i).getTitle().equals(taskName)){
				return taskList.get(i);
			}
		}
		return null;
	}

	public Task[] getAllTasks() {
		Task[] tempArr = new Task[taskList.size()];
		taskList.toArray(tempArr);
		return tempArr;
	}
	
	public boolean hasTask(String taskName) {
		for(int i = 0;i<taskList.size();i++){
			if(taskList.get(i).getTitle().equals(taskName)){
				return true;
			}
		}
		return false;
	}

} // End of TaskList class.